package com.changgou.controller;

import entity.Result;
import entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @auther LiZiBa
 * @date 2020/7/18 13:53
 * @description:
 **/

@ControllerAdvice // 全局异常捕获，@RequestMapping注解下的异常都会捕获
public class BaseExceptionHandler {

    /**
     * 异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){

        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }
}
